<template>
	<el-config-provider :locale="currentElementPlusLocale">
		<router-view />
	</el-config-provider>
</template>

<script setup>
import { ref, onMounted, onUnmounted } from 'vue'
import { ElConfigProvider } from 'element-plus'
import {
	getCurrentElementPlusLocale,
	onElementPlusLocaleChange,
	offElementPlusLocaleChange,
} from '@/utils/languageManager'

import { lStorage } from '@/utils/storage'
if (!lStorage.get('theme')) {
	lStorage.set('theme', 'dark')
}
if (!lStorage.get('language')) {
	lStorage.set('language', 'zh')
}

const currentElementPlusLocale = ref(getCurrentElementPlusLocale())

// 语言变化处理函数
const handleLocaleChange = (newLocale) => {
	currentElementPlusLocale.value = newLocale
}

onMounted(() => {
	// 注册语言变化监听
	onElementPlusLocaleChange(handleLocaleChange)
})

onUnmounted(() => {
	// 移除语言变化监听
	offElementPlusLocaleChange(handleLocaleChange)
})
</script>

<style lang="scss">
@import url('@/styles/main.scss');
</style>
